package Adapter.After;

/**
 * Here we get a monster class from someone else. It has the
 * functionality that we need but it was created completely differently.
 * We could refactor it but that could be a problem at times because we
 * may have to change a large amount of classes.
 */
public class Game
{
    public static void main( String[] args )
    {
        Monster monster = new MegaMonsterAdapter(); //Now we can use our mega monster! It's epic win!
        monster.takesDamage( 25 );
    }
}

interface Monster
{
    void takesDamage( int damage );
    int  givesDamage();
    boolean isTimeToAttack();
}

class OurMonster implements Monster
{
    int life = 100;

    public void takesDamage( int damage )
    {
        life = life - damage;
    }

    public int givesDamage()
    {
        return 25;
    }

    public boolean isTimeToAttack()
    {
        return false;
    }
}

/**
 * Now everything can work perfectly. Our monster acts just the same
 */
class MegaMonsterAdapter implements Monster
{
    MegaMonster megaMonster = new MegaMonster();

    public void takesDamage( int damage )
    {
        megaMonster.getsHit( damage );
    }

    public int givesDamage()
    {
        return megaMonster.attacks();
    }

    public boolean isTimeToAttack()
    {
        return false;
    }
}

/**
 * This class can now be used just like any other monster class can be.
 */
class MegaMonster
{
    int life = 100;

    public int attacks()
    {
        return 35;
    }

    public void getsHit( int damage )
    {
        life = life - damage;
    }
}
